package com.efun.framework.autoconfigure;

import org.springframework.boot.context.properties.ConfigurationProperties;

import java.util.Properties;

/**
 * 用于对应Druid数据元的特殊的属性
 * @author kinven on 17-7-28.
 */
@ConfigurationProperties(prefix = "efun.druid")
public class DruidProperties {

    private static final String CONFIG_DECRYPT="config.decrypt";
    private static final String CONFIG_DECRYPT_KEY="config.decrypt.key";
    private static final String DEFAULT_CONFIG_FILTERS="config,log4j2";

    private boolean isDecrypt = false;
    private String publicKey;
    private String privateKey;
    private String filters = DEFAULT_CONFIG_FILTERS;


    public boolean isDecrypt() {
        return isDecrypt;
    }

    public void setDecrypt(boolean decrypt) {
        isDecrypt = decrypt;
    }

    public String getPublicKey() {
        return publicKey;
    }

    public void setPublicKey(String publicKey) {
        this.publicKey = publicKey;
    }

    public String getPrivateKey() {
        return privateKey;
    }

    public void setPrivateKey(String privateKey) {
        this.privateKey = privateKey;
    }

    public String getFilters() {
        return filters;
    }

    public void setFilters(String filters) {
        this.filters = filters;
    }

    public Properties connectProperties(){
        Properties p = new Properties();
        if(isDecrypt && null != publicKey) {
            p.setProperty(CONFIG_DECRYPT,"true");
            p.setProperty(CONFIG_DECRYPT_KEY,publicKey);
        }
        return p;
    }
}
